package com.iseastar.guojiang.team;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.TextView;

import com.iseastar.BaseActivity2;
import com.shouhuobao.station.R;

import droid.frame.fragmentation.SupportFragment;

/**
 * 全网战区排行
 * Created by lidandan on 2018/6/14.
 */
public class CourierAllTeamRankingListActivity extends BaseActivity2 implements View.OnClickListener {

    private TextView mThisProvinceTV, mNationwideTeamTV;
    private SupportFragment[] mFragments = new SupportFragment[2];
    int position = 0;
    int prePosition = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        if (savedInstanceState == null) {
//            mFragments[0] = new CourierThisProvinceFragment();
//            mFragments[1] = new CourierNationwideFragment();
//            loadMultipleRootFragment(R.id.fl_ranking, 0, mFragments);
//        } else {
//            // 这里库已经做了Fragment恢复,所有不需要额外的处理了, 不会出现重叠问题
//
//            // 这里我们需要拿到mFragments的引用,也可以通过getSupportFragmentManager.getFragments()自行进行判断查找(效率更高些),用下面的方法查找更方便些
//            mFragments[0] = findFragment(CourierThisProvinceFragment.class);
//            mFragments[1] = findFragment(CourierNationwideFragment.class);
//        }
        setFragmentIndicator(position);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.courier_all_team_ranking_list_activity);
        super.findViewById();
        getAppTitle().setCommonTitle("战队中心");
        //本省
        mThisProvinceTV = (TextView) findViewById(R.id.this_province_tv);
        mThisProvinceTV.setOnClickListener(this);
        //全国
        mNationwideTeamTV = (TextView) findViewById(R.id.nationwide_team_tv);
        mNationwideTeamTV.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //本省
            case R.id.this_province_tv:
                prePosition = position;
                position = 0;
                if (position == prePosition) {
                    return;
                }
                mThisProvinceTV.setTextColor(getResources().getColor(R.color.white));
                mThisProvinceTV.setBackgroundResource(R.drawable.courier_all_team_left_checked_bg);
                mNationwideTeamTV.setTextColor(getResources().getColor(R.color.app_theme_color1));
                mNationwideTeamTV.setBackgroundColor(getResources().getColor(R.color.transparent));
                showHideFragment(mFragments[position], mFragments[prePosition]);
                break;
            //全国
            case R.id.nationwide_team_tv:
                prePosition = position;
                position = 1;
                if (position == prePosition) {
                    return;
                }
                mNationwideTeamTV.setTextColor(getResources().getColor(R.color.white));
                mNationwideTeamTV.setBackgroundResource(R.drawable.courier_all_team_right_checked_bg);
                mThisProvinceTV.setTextColor(getResources().getColor(R.color.app_theme_color1));
                mThisProvinceTV.setBackgroundColor(getResources().getColor(R.color.transparent));
                showHideFragment(mFragments[position], mFragments[prePosition]);
                break;
        }
    }

    private void setFragmentIndicator(int whichIsDefault) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        mFragments[0] = (SupportFragment) fragmentManager
                .findFragmentById(R.id.fragment_province);
        mFragments[1] = (SupportFragment) fragmentManager
                .findFragmentById(R.id.fragment_nationwide);
        fragmentManager.beginTransaction().hide(mFragments[0])
                .hide(mFragments[1]).show(mFragments[whichIsDefault]).commit();
    }
}
